<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>embedme: libemb::Semaphore Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="logo.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">embedme
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>libemb</b></li><li class="navelem"><a class="el" href="classlibemb_1_1_semaphore.html">Semaphore</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pro-attribs">Protected Attributes</a> &#124;
<a href="classlibemb_1_1_semaphore-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">libemb::Semaphore Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>信号量类(基于POSIX接口) <br  />
  
 <a href="classlibemb_1_1_semaphore.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="_thread_util_8h_source.html">ThreadUtil.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a53bb52d22ce9e0ecc2fad6a2832dd426"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a53bb52d22ce9e0ecc2fad6a2832dd426">Semaphore</a> (const char *name=NULL)</td></tr>
<tr class="memdesc:a53bb52d22ce9e0ecc2fad6a2832dd426"><td class="mdescLeft">&#160;</td><td class="mdescRight">信号量  <a href="classlibemb_1_1_semaphore.html#a53bb52d22ce9e0ecc2fad6a2832dd426">More...</a><br /></td></tr>
<tr class="separator:a53bb52d22ce9e0ecc2fad6a2832dd426"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a363fad413d5fbe26a8c6bdf267fc5fd1"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a363fad413d5fbe26a8c6bdf267fc5fd1">open</a> (int value=-1)</td></tr>
<tr class="memdesc:a363fad413d5fbe26a8c6bdf267fc5fd1"><td class="mdescLeft">&#160;</td><td class="mdescRight">打开信号量  <a href="classlibemb_1_1_semaphore.html#a363fad413d5fbe26a8c6bdf267fc5fd1">More...</a><br /></td></tr>
<tr class="separator:a363fad413d5fbe26a8c6bdf267fc5fd1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a30b722f5f9e6f6a867abdc62efd1629d"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a30b722f5f9e6f6a867abdc62efd1629d">close</a> ()</td></tr>
<tr class="memdesc:a30b722f5f9e6f6a867abdc62efd1629d"><td class="mdescLeft">&#160;</td><td class="mdescRight">关闭信号量  <a href="classlibemb_1_1_semaphore.html#a30b722f5f9e6f6a867abdc62efd1629d">More...</a><br /></td></tr>
<tr class="separator:a30b722f5f9e6f6a867abdc62efd1629d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a866dd6c3990e301ac10ddfedc4eae767"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a866dd6c3990e301ac10ddfedc4eae767">unlink</a> ()</td></tr>
<tr class="memdesc:a866dd6c3990e301ac10ddfedc4eae767"><td class="mdescLeft">&#160;</td><td class="mdescRight">删除信号量  <a href="classlibemb_1_1_semaphore.html#a866dd6c3990e301ac10ddfedc4eae767">More...</a><br /></td></tr>
<tr class="separator:a866dd6c3990e301ac10ddfedc4eae767"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab2da514c4f3d69cbb985c54a389c6cec"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#ab2da514c4f3d69cbb985c54a389c6cec">wait</a> ()</td></tr>
<tr class="memdesc:ab2da514c4f3d69cbb985c54a389c6cec"><td class="mdescLeft">&#160;</td><td class="mdescRight">等待信号量  <a href="classlibemb_1_1_semaphore.html#ab2da514c4f3d69cbb985c54a389c6cec">More...</a><br /></td></tr>
<tr class="separator:ab2da514c4f3d69cbb985c54a389c6cec"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a37cbf6ce273d11ae0854d624c47ba8e8"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a37cbf6ce273d11ae0854d624c47ba8e8">tryWait</a> ()</td></tr>
<tr class="memdesc:a37cbf6ce273d11ae0854d624c47ba8e8"><td class="mdescLeft">&#160;</td><td class="mdescRight">尝试等待信号量  <a href="classlibemb_1_1_semaphore.html#a37cbf6ce273d11ae0854d624c47ba8e8">More...</a><br /></td></tr>
<tr class="separator:a37cbf6ce273d11ae0854d624c47ba8e8"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae25af7e2a288cf351cd20de525d07f47"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#ae25af7e2a288cf351cd20de525d07f47">post</a> ()</td></tr>
<tr class="memdesc:ae25af7e2a288cf351cd20de525d07f47"><td class="mdescLeft">&#160;</td><td class="mdescRight">释放信号量  <a href="classlibemb_1_1_semaphore.html#ae25af7e2a288cf351cd20de525d07f47">More...</a><br /></td></tr>
<tr class="separator:ae25af7e2a288cf351cd20de525d07f47"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a72ccf6c042741028774e20d9e2d38281"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classlibemb_1_1_semaphore.html#a72ccf6c042741028774e20d9e2d38281">getValue</a> (int &amp;value)</td></tr>
<tr class="memdesc:a72ccf6c042741028774e20d9e2d38281"><td class="mdescLeft">&#160;</td><td class="mdescRight">获取信号量值  <a href="classlibemb_1_1_semaphore.html#a72ccf6c042741028774e20d9e2d38281">More...</a><br /></td></tr>
<tr class="separator:a72ccf6c042741028774e20d9e2d38281"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pro-attribs"></a>
Protected Attributes</h2></td></tr>
<tr class="memitem:ab3f7f3dc0399f5c1ca2e5e1cd1ccb5aa"><td class="memItemLeft" align="right" valign="top"><a id="ab3f7f3dc0399f5c1ca2e5e1cd1ccb5aa"></a>
sem_t&#160;</td><td class="memItemRight" valign="bottom"><b>m_sem</b></td></tr>
<tr class="separator:ab3f7f3dc0399f5c1ca2e5e1cd1ccb5aa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:acb783d2e676e098c700f8eb290c0dce9"><td class="memItemLeft" align="right" valign="top"><a id="acb783d2e676e098c700f8eb290c0dce9"></a>
std::string&#160;</td><td class="memItemRight" valign="bottom"><b>m_name</b></td></tr>
<tr class="separator:acb783d2e676e098c700f8eb290c0dce9"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>信号量类(基于POSIX接口) <br  />
 </p>
<dl class="section note"><dt>Note</dt><dd>无名信号量用于线程间通信,有名信号量用于进程间通信 </dd></dl>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a53bb52d22ce9e0ecc2fad6a2832dd426"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a53bb52d22ce9e0ecc2fad6a2832dd426">&#9670;&nbsp;</a></span>Semaphore()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">libemb::Semaphore::Semaphore </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em> = <code>NULL</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">name</td><td>名称中不能包含'/',name=NULL时表示创建无名信号量 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section note"><dt>Note</dt><dd>分为无名信号量和有名信号量,无名信号量用于线程间通信,有名信号量用于进程间通信 <br  />
 </dd></dl>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a30b722f5f9e6f6a867abdc62efd1629d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a30b722f5f9e6f6a867abdc62efd1629d">&#9670;&nbsp;</a></span>close()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::close </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>关闭信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>对于有名信号量,关闭信号量不会真正删除信号量,还需要调用unlink() </dd></dl>

</div>
</div>
<a id="a72ccf6c042741028774e20d9e2d38281"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a72ccf6c042741028774e20d9e2d38281">&#9670;&nbsp;</a></span>getValue()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::getValue </td>
          <td>(</td>
          <td class="paramtype">int &amp;&#160;</td>
          <td class="paramname"><em>value</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>获取信号量值 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">value</td><td>当前值 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>当value&gt;0说明有资源,=0无资源,&lt;0表示有|value|个线程在等待资源 </dd></dl>

</div>
</div>
<a id="a363fad413d5fbe26a8c6bdf267fc5fd1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a363fad413d5fbe26a8c6bdf267fc5fd1">&#9670;&nbsp;</a></span>open()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::open </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>value</em> = <code>-1</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>打开信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">value</td><td>只有有名信号量存在时,可以不指定该值 </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>信号量存在,则返回,不存在则创建 </dd></dl>

</div>
</div>
<a id="ae25af7e2a288cf351cd20de525d07f47"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae25af7e2a288cf351cd20de525d07f47">&#9670;&nbsp;</a></span>post()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::post </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>释放信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>使信号量值增加1,释放资源 </dd></dl>

</div>
</div>
<a id="a37cbf6ce273d11ae0854d624c47ba8e8"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a37cbf6ce273d11ae0854d624c47ba8e8">&#9670;&nbsp;</a></span>tryWait()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::tryWait </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>尝试等待信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>使信号量值减1,如果无资源可申请,则返回. </dd></dl>

</div>
</div>
<a id="a866dd6c3990e301ac10ddfedc4eae767"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a866dd6c3990e301ac10ddfedc4eae767">&#9670;&nbsp;</a></span>unlink()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::unlink </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>删除信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>该方法仅对有名信号量有效 </dd></dl>

</div>
</div>
<a id="ab2da514c4f3d69cbb985c54a389c6cec"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab2da514c4f3d69cbb985c54a389c6cec">&#9670;&nbsp;</a></span>wait()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool libemb::Semaphore::wait </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>等待信号量 </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>成功返回true,失败返回false </dd></dl>
<dl class="section note"><dt>Note</dt><dd>使信号量值减1,如果无资源可申请,则阻塞. </dd></dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li>src/<a class="el" href="_thread_util_8h_source.html">ThreadUtil.h</a></li>
<li>src/ThreadUtil.cpp</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
</html>
